require("../util.js");
require("../component/components.js");
require("../component/footer.js");
require("../../jsMt/util.js");
var userInfo=JSON.parse(sessionStorage.getItem("userInfo"));
if(!userInfo){
    location.href="/loginIndex"
}
var vm = new Vue({
    el:"#enjoyIndex",
    data:{
        loadFlag:false,
        pageNumber:1,
        dataInfo:{},
        productList:{},
        productList1:[],
        productList2:[],
        normalCoupon:{},
        normalCoupon1:[],
        normalCoupon2:[]
    },
    mounted:function(){
        this.myData();
        this.myProduct();
        this.myNormalCoupon();
    },
    methods:{
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //推荐用户
        myData:function(){
            var that=this,data;
            data={
                loginUid:userInfo.loginUid
            };
            this.ajax({url:"/enjoy/myData",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.dataInfo=b.json.data;
                }else{
                    vm.$refs.prompt.toast("获取数据失败！");
                }
            });
        },
        //我的商品列表
        myProduct:function(){
            var that=this,data;
            data={
                loginUid:userInfo.loginUid,
                pageNumber:that.pageNumber
            };
            this.ajax({url:"/enjoy/myProduct",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.productList=b.json.data;
                    that.productList1=that.productList.list;
                    if(that.productList.pageNumber>1){
                        if(that.productList.list.length>0) {
                            that.productList2 = that.productList2.concat(b.json.data.list);
                        }
                    }else{
                        that.productList2= that.productList1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.productList={};
                    that.productList1=[];
                    that.productList2=[];
                    vm.$refs.prompt.toast("获取数据失败！");
                }
            });
        },
        //我的优惠券列表
        myNormalCoupon:function(){
            var that=this,data;
            data={
                loginUid:userInfo.loginUid,
                pageNumber:that.pageNumber
            };
            this.ajax({url:"/enjoy/myNormalCoupon",data:data,dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.normalCoupon=b.json.data;
                    that.normalCoupon1=that.normalCoupon.list;
                    if(that.normalCoupon.pageNumber>1){
                        if(that.normalCoupon.list.length>0) {
                            that.normalCoupon2 = that.normalCoupon2.concat(b.json.data.list);
                        }
                    }else{
                        that.productList2= that.normalCoupon1;
                    }
                    vm.loadFlag=false;
                }else{
                    that.normalCoupon={};
                    that.normalCoupon1=[];
                    that.normalCoupon2=[];
                    vm.$refs.prompt.toast("获取数据失败！");
                }
            });
        }
    }
    ,watch:{

    }
});